import { createI18n } from 'vue-i18n/dist/vue-i18n.mjs';     // 修改后
const zhCn = require("element-plus/dist/locale/zh-cn.mjs")
const En = require("element-plus/dist/locale/en.mjs")
import zh from "@/i18n/language/zh";
import en from "@/i18n/language/en"
// 国际化语言资源

const messages = {
    en: {
        ...En,
        ...en
    },
    zh: {
        ...zhCn,
        ...zh
    }
}

// 获取

function getLocal() {
    // 如果缓存存在，则直接返回
    const myLocale = localStorage.getItem('my_locale');
    if (myLocale) {
        return myLocale;
    }
    // 否则读取当前网页语言
    const localName = navigator.language.indexOf('zh') !== -1 ? 'zh' : 'en'
    // 设置缓存
    localStorage.setItem('my_locale', localName)
    return localName
}

// 创建i8n实例
export const i18n = createI18n({
    locale: getLocal(),
    messages,
    warnHtmlMessage: false
})